﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MyMainSite.Models
{
    public class SearchIndexModel : BaseModel
    {
        #region Public Methods

        public SearchIndexModel(string term)
        {
            this.BreadCrumb.Add(new KeyValuePair<string, string>(term, String.Empty));

            this.Search(term);
        }

        #endregion

        #region Public Methods

        private void Search(string term)
        {
            term = term.ToLower().Trim();

            RichardsSiteEntities dc = new RichardsSiteEntities();

            this.BlogEntries = (from e in dc.BlogEntries
                                where e.Title.ToLower().Contains(term) ||
                                    e.BodyText.ToLower().Contains(term)
                                select e).ToList();

            this.Projects = (from p in dc.Projects
                             where p.Name.ToLower().Contains(term) ||
                                p.Description.ToLower().Contains(term)
                             select p).ToList();
        }

        #endregion
    }
}